﻿

function isEmpty(val){
    if(val == null || val == undefined || val == ''){
        return null;
    } else {
        return val;
    }
}

layui.use(['table','form'], function(){
    var form = layui.form;
    form.on('submit(sendData)', function(data){
            layer.confirm('确认修改?', {icon: 3, title:'警告'}, function(index) {
                var typeId = $('#button_store').val();
                var a=GetRequest();
                var tableid=a['tableId'];
                var jsonArr = new Array();
                var index=0;
                for(let i = 1; i <= $("#pm_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#jszx_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 2;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#jszx_num").val());
                    jsonIndex['money'] = isEmpty($('#jszx_money').val());
                    jsonIndex['name'] = $('#jszx_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#jszx_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#jszx_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#app_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 3;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#app_designer_num").val());
                    jsonIndex['money'] = isEmpty($('#app_designer_money').val());
                    jsonIndex['name'] = $('#app_designer_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#app_designer_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#app_designer_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#platform_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#platform_designer_num").val());
                    jsonIndex['money'] = isEmpty($('#platform_designer_money').val());
                    jsonIndex['name'] = $('#platform_designer_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#platform_designer_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#platform_designer_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#client_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#web_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#ui_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#java_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#andriod_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#App_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#C_designer_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 1;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#pm_num").val());
                    jsonIndex['money'] = isEmpty($('#pm_money').val());
                    jsonIndex['name'] = $('#pm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#pm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#pm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#web_designer_2_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 12;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#web_designer_2_num").val());
                    jsonIndex['money'] = isEmpty($('#web_designer_2_money').val());
                    jsonIndex['name'] = $('#web_designer_2_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#web_designer_2_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#web_designer_2_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#test_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 13;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#test_num").val());
                    jsonIndex['money'] = isEmpty($('#test_money').val());
                    jsonIndex['name'] = $('#test_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#test_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#test_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#bm_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 14;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#bm_num").val());
                    jsonIndex['money'] = isEmpty($('#bm_money').val());
                    jsonIndex['name'] = $('#bm_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#bm_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#bm_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#implement_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 15;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#implement_num").val());
                    jsonIndex['money'] = isEmpty($('#implement_money').val());
                    jsonIndex['name'] = $('#implement_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#implement_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#implement_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#project_director_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 16;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#project_director_num").val());
                    jsonIndex['money'] = isEmpty($('#project_director_money').val());
                    jsonIndex['name'] = $('#project_director_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#project_director_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#project_director_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                for(let i = 1; i <= $("#tech_director_num").val(); i++) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['site'] = 17;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['num'] = isEmpty($("#tech_director_num").val());
                    jsonIndex['money'] = isEmpty($('#tech_director_money').val());
                    jsonIndex['name'] = $('#tech_director_name_'+i).val();
                    jsonIndex['planDay'] = isEmpty($('#tech_director_num_'+i).val());
                    jsonIndex['totalDay'] = isEmpty($('#tech_director_totalnum_'+i).val());
                    jsonArr[index++] = jsonIndex;
                }
                if(jsonArr == null || index == 0) {
                    var jsonIndex = {};
                    jsonIndex['level1SystemId'] = tableid;
                    jsonIndex['typeId'] = typeId;
                    jsonIndex['site'] = -1;
                    jsonArr[index++] = jsonIndex;
                }
                index--;
                //console.log( JSON.stringify(jsonArr));
                $.ajax({
                    type:'post',
                    dateType: "json",
                    contentType : "application/json",
                    url:"/contract/saveWorkPlan",
                    data:JSON.stringify( jsonArr ),
                    success: function (res) {
                        //console.log(res)
                        if(res.msg == 'success') {
                            layer.msg("修改成功！ 页面即将关闭！ ");
                            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                            //console.log(index);
                            //parent.layer.close(index);//关闭弹出的子页面窗口*!/
                            setTimeout(
                                function(){
                                    parent.layer.close(index);//关闭弹出的子页面窗口*!/
                                },1000)
                        } else {
                            layer.msg('修改失败');
                        }
                    }
                });
                layer.close(index);
            });
            return false;
        });
});

